﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace Factory
{
   public class SessionFactory
    {
        public static T CreateDAO<T>()
        {
            //根据配置文件拿到指定的程序集
            string dllName = ConfigurationManager.AppSettings["DllName"];
            Assembly asse = Assembly.Load(dllName);
            Type[] types = asse.GetTypes();
            object dao = null;
            foreach (Type t in types)
            {
                if (typeof(T).IsAssignableFrom(t))
                {
                    dao = Activator.CreateInstance(t);
                    break;
                }
            }
            return (T)dao;
        }
        public static int SaveChanges()
        {
                return DbContextFactory.GetDbContext().SaveChanges();            
            
        }
    }
}
